package math2;

import fem2.BasisManager;
import fem2.MeshPart;
import fem2.Node;

public class IsoparametricEdgeGeometry extends IsoparametricGeometry {

	private static IsoparametricEdgeGeometry instance = new IsoparametricEdgeGeometry();

	private IsoparametricEdgeGeometry() {
	}

	/**
	 * Get the instance of IsoparametricEdgeGeometry singleton
	 * 
	 * @return the Singleton instance
	 */
	public static IsoparametricEdgeGeometry getInstance() {
		return instance;
	}

	@Override
	public double[][] jacobianAt(MeshPart mp, double... xi) {
		int dim = mp.getDimension();
		double[] J = new double[dim];
		Node[] nodes = mp.getNodes();
		FunctionBasisOnRnToR basis = BasisManager.getInstance().getBasis(mp.getType());
		for (int i = 0; i < nodes.length; i++) {
			FunctionRnToR Ni = basis.getBasisFunction(i);
			double[] dNi = Ni.gradientAt(xi);
			double[] X = nodes[i].getPosition();
			for (int j = 0; j < dim; j++) {
				J[j] += dNi[0] * X[j];
			}
		}
		return new double[][] { J };
	}

}
